<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *群发邮件
 *@author : KevinBai
 *
 **/
class Emailsender_model extends MY_Model
{
	public function __construct()
	{
		parent::__construct();
	}	
	/**
	 * 插入群发发送数据tr_emailsender表
	 */
	public function insert_data($data = array())
	{
      $this->db->insert("tr_emailsender", $data);
		  return $this->db->insert_id();
	}
    
    /**
	 * 更新群发发送草稿数据tr_emailsender表
	 */
	public function update_data($draftid,$data = array())
	{
	    $this->db->where("id",$draftid);
        $res = $this->db->update("tr_emailsender", $data);
		return $res;
	}
    /**
	 * 获取历史记录
	 */
	public function get_history_list($sortname, $order,$limit="0,20",$type)
	{
	   $sql = "SELECT * FROM tr_emailsender WHERE 1 ";
       if(!empty($type))
       {
        $sql .= " AND draft_status = 1";
       }
       else
       {
        $sql .= " AND draft_status = 0";
       }
       if(!empty($sortname))
       {
        $sql .= " ORDER BY $sortname $order ";
       }
       else
       {
        $sql .= " ORDER BY addtime desc";
       }
       if(!empty($limit))
       {
        $sql .= " LIMIT $limit";
       }
       $query = $this->db->query($sql);
	   return $query->result_array();
	}
    /**
	 * 获取历史记录
	 */
	public function get_history_cnt($type)
	{
	   $sql = "SELECT * FROM tr_emailsender WHERE 1 ";
       if(!empty($type))
       {
        $sql .= " AND draft_status = 1";
       }
       else
       {
        $sql .= " AND draft_status = 0";
       }
       $query = $this->db->query($sql);
	   return $query->num_rows();
	}
    /**
     * 根据ID删除草稿信息
     */
     public function del_draft($id = "")
     {
        $this->db->where("id", $id);
        $res = $this->db->delete("tr_emailsender");
        return $res;
     }
    /**
	 * 根据邮件id、ackey获取内容
	 */
	public function get_emailsender_by($id = 0)
	{
	   if(!empty($id))
       {
        $this->db->where("id",$id);
       }
       $query = $this->db->get("tr_emailsender");
	   return $query->row_array();
	}   
   
    
    /**
	 * 根据id获取邮件草稿信息
	 */
	public function get_email_draft_byid($id)
	{

       $this->db->where("id",$id);
       $query = $this->db->get("tr_emailsender");
	   return $query->row_array();
	}
   

  public function do_push($insertData_str){
        $sql = "INSERT INTO tr_message_push_map (type,typeid,to_userid,from_userid,createtime,from_username) values {$insertData_str}";
        $result = $this->db->query($sql);
        return $this->db->insert_id();
  }
 
}

/* End of file emailsender_model.php */
/* Location: ./application/models/emailsender_model.php */
